home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: fwrite help?
- Date: 12 Feb 1996 17:52:03 -0500
- Organization: Montclair State University
- Message-ID: <harmon.824165113@pegasus.montclair.edu>
- References: <4fmaig$7of@news.global1.net>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- youngrc@global1.net writes:
- >What would the syntax for fwrite be to output 8 characters of
- >char line[10] to a file? K&R doesn't write much about it. Thanks
- >for the help.
-
- size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream); is the
- prototype I have. You can use line to devolve into a pointer towards the
- first element in line, sizeof(char) for size insures compatibility on machines
- where a character is more than one byte, and since you want 8 characters, set
- n to 8.
-
- : fwrite( line, sizeof(char), 8, fp);
-
- Of course, when they are contiguous in an array, and you know the sizeof a
- char is 1 byte, it's much more efficient to say you want to write an 8-byte
- block of memory once, instead of a 1-byte block of memory eight times.
-
- -- Stone
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... On a clear disk, you can seek forever.
-